app.controller('UploadCtrl',function($scope,$localStorage){
        
        $('#file_upload').uploadify({
            'swf'      : 'js/uploadify/uploadify.swf',   
            'uploader' : "http://118.178.136.209/index.php?r=admin-user/upload-head-img",
            'buttonText': '上传头像',
            'fileObjName' : 'picture',
            'fileTypeDesc' : '选择文件',
            'fileTypeExts' : '*.jpg;*.png;',
            'method' : 'post',
            'formData':{'token':$localStorage.token},
            'fileSizeLimit':'10MB',
            'auto' : true,
            'multi' : false,
            'onUploadSuccess' : function(file,data,response) {
              
              var filedata = JSON.parse(data);
              if(filedata.code==0&&filedata.msg=="上传成功") {
                $("#head_img").val(filedata.data);
                $("#upimg").attr('src','http://118.178.136.209/'+filedata.data);
                $("#file_uploaded11").text(filedata.data+"上传完成");
              }
              
              
              
            }
        });
   
})

app.controller('ModifyUserController',function ($scope,$http,$location,$window,$state,$localStorage) {
	$http.post(
        $scope.app.backendurl+"admin-user/view-user",
        {
           
            'username': $localStorage.cur_user.uname,                             
            'token':$localStorage.token                   

        }
    ).success(function (data) {
      //console.log(data);
      if(data.code==0&&data.msg=="成功"){
        $scope.aaData = data.data.user;   
        $scope.user =  data.data.user; 
        $("#version").val(data.data.user.version)
      }
       if(data.code==20001){
         $location.path('access.signin');
       }
    }).error(function (data) {
        alert(data);
    })

    $scope.save = function(){
       //console.log($("#head_img").val());
        $http.post(
              $scope.app.backendurl+"admin-user/update-user",
              {
                  'user_id': $localStorage.cur_user.user_id,
                  'name': $scope.user.name,
                  'username': $scope.user.uname,                           
                  'genter':$scope.user.genter,
                  'phone':$scope.user.phone,
                  'mail':$scope.user.mail ,
                  'apartment':$scope.user.apartment, 
                  'post':$scope.user.post,
                  'head_img':$("#upimg").attr('src'),  
                  'version':$("#version").val(),               
                  'token':$localStorage.token                         

              }
          ).success(function (data) {
          //console.log(data);
            if(data.code==0&&data.msg=="更新用户资料成功"){
              alert(data.msg);
              $state.go('app.user.info');

            }
          

             if(data.code==20001){
               $location.path('access.signin');
             }
          }).error(function (data) {
              alert(data);
          })
      }

          


})